//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core;
using OpenLS.Core.Serialization;
using OpenLS.Vml.Serialization;

namespace OpenLS.Vml
{
    public class ImageData: ShapeElement
    {
        internal const string xmlName = "imagedata";
        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                ImageAttributes.ReadXml(c);
                Id = c.GetOptionalString("id");
                ChromaKey = c.GetOptionalString("chromakey");
                EmbossColor = c.GetOptionalString("embosscolor");
                ReColorTarget = c.GetOptionalString("recolortarget");
                AltHRef = c.GetOptionalString(VmlConstants.OfficeNamespace + "althref");
                Title = c.GetOptionalString(VmlConstants.OfficeNamespace + "title");
                OleId = c.GetOptionalString(VmlConstants.OfficeNamespace + "oleid");
                DetectMouseClick = c.GetOptionalString(VmlConstants.OfficeNamespace + "detectmouseclick");
                movie = c.GetOptionalString(VmlConstants.OfficeNamespace + "movie");
                string relid = c.GetOptionalString(VmlConstants.OfficeNamespace + "relid");
                if (relid != null)
                {
                    Data = c.GetInlinePart(relid);
                }
                string rId = c.GetOptionalString(OfficeConstants.RelationshipNamespace + "id");
                if (rId != null)
                    this._img = VmlImage.Load(c, rId);
                string pict = c.GetOptionalString(OfficeConstants.RelationshipNamespace + "pict");
                if (pict != null)
                    this._AlternateImageData = VmlImage.Load(c, pict);
                HRef = c.GetOptionalString(OfficeConstants.RelationshipNamespace + "href");

            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write(xmlName))
            {
                ImageAttributes.WriteXml(c);
                c.SetOptionalString("id", Id);
                c.SetOptionalString("chromakey", ChromaKey);
                c.SetOptionalString("embosscolor", EmbossColor);
                c.SetOptionalString("recolortarget", ReColorTarget);
                c.SetOptionalString(VmlConstants.OfficeNamespace + "althref", AltHRef);
                c.SetOptionalString(VmlConstants.OfficeNamespace + "title", Title);
                c.SetOptionalString(VmlConstants.OfficeNamespace + "oleid", OleId);
                c.SetOptionalString(VmlConstants.OfficeNamespace + "detectmouseclick", DetectMouseClick);
                c.SetOptionalString(VmlConstants.OfficeNamespace + "movie", movie);
                if (Data != null)
                {
                    string relid = c.WriteInlinePart(Data);
                    c.SetOptionalString(VmlConstants.OfficeNamespace + "relid", relid);
                }
                if (_img != null)
                    _img.Write(c, "image");
                if (_AlternateImageData != null)
                    _AlternateImageData.Write(c, "alternateImage", "pict");
                //c.SetOptionalString(OfficeConstants.RelationshipNamespace + "pict", pict);
               //\\ c.SetOptionalStringWithNamespace("href", OfficeConstants.RelationshipNamespace  , HRef);

            }
        }

        string _movie;
        public string movie
        {
            get
            {
                return _movie;
            }
            set
            {
                _movie = value;
            }
        }
        string _id;
        public string Id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }
        private CachedPart _data;

        public CachedPart Data
        {
            get { return _data; }
            set { _data = value; }
        }
	
        string _href;
        public string HRef
        {
            get
            {
                return _href;
            }
            set
            {
                _href = value;
            }
        }
        
        private string _detectmouseclick;

        public string DetectMouseClick
        {
            get { return _detectmouseclick; }
            set { _detectmouseclick = value; }
        }
	
        private string _oleid;

        public string OleId
        {
            get { return _oleid; }
            set { _oleid = value; }
        }
	

        private string _title;

        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
	

        private string _althref;

        public string AltHRef
        {
            get { return _althref; }
            set { _althref = value; }
        }
	

        private string _recolortarget;

        public string ReColorTarget
        {
            get { return _recolortarget; }
            set { _recolortarget = value; }
        }
	

        private string _embosscolor;

        public string EmbossColor
        {
            get { return _embosscolor; }
            set { _embosscolor = value; }
        }
	
        private string _chromakey;

        public string ChromaKey
        {
            get { return _chromakey; }
            set { _chromakey = value; }
        }
	

	
        private readonly ImageAttributes _ImageAttributes = new ImageAttributes();
        private VmlImage _img;
        private VmlImage _AlternateImageData;

        internal ImageAttributes ImageAttributes
        {
            get { return _ImageAttributes; }
        }
	
    }
}
